﻿/* Filename: Tile.as 
 *
 * Description: This class creates Tile objects that
 * correspond to stored graphics.  This class is used
 * with Map.as to make visual maps.
 *
 * Tyler Samson
 * Feb 2008
 * @ Sierra Nevada College
 */
class Tile extends ElementType {
	private var _tileName:String;
	private var _tileX:Number;					// tile location X in the map
	private var _tileY:Number;					// tile location Y in the map
	private var _graphicName:String;			// name of graphic that represents tile
	private var _graphicFormat:String = ".png"	// format of the stored graphic
	private var _demon:Demon = null;			// holds demon occupying this tile
	private var _isTarget:Boolean = false;		// indicate if this tile is a target for an attack/item
	private var _originalType:String;
	private var _counter:Number = -1;
	
	public function Tile(p_tileName:String, p_elementType:String, p_tileX:Number, p_tileY:Number) {
		super(p_elementType);					// Set the element type of this attack
		_tileName = p_tileName;
		_tileX = p_tileX;
		_tileY = p_tileY;
		_originalType = p_elementType;
	}
	
	// Return the name of the graphic in storage
	public function graphicName():String {
		var _graphicName:String = "tiles/tile" + getElementType() + _graphicFormat;
		return _graphicName;
	}
	
	// Return the name of the tile object
	public function getName():String {
		return _tileName;
	}
	
	// Return this tile's location X in the map
	public function getX():Number {
		return _tileX;
	}
	
	// Return this tile's location Y in the map
	public function getY():Number {
		return _tileY;
	}
	
	// Return true if this tile is a target for an attack/item
	public function getIsTarget():Boolean {
		return _isTarget;
	}
	
	// Return the demon this file contains (null if one does not exist)
	public function getDemon():Demon {
		return _demon;
	}
	
	// Add demon to tile
	public function addDemon(p_demon:Demon):Void {
		_demon = p_demon;
	}
	
	// Remove demon from tile
	public function removeDemon():Void {
		_demon = null;
	}
	
	// Set whether this tile is a target for attack/item or not
	public function setIsTarget(p_value:Boolean):Void {
		_isTarget = p_value;
	}
	
	public function setNewType(p_elementType:String):Void {
		_elementType = _elementTypes[p_elementType];
	}
	
	public function setCounter(p_counter:Number) {
		_counter = p_counter;
	}
	
	public function changeCounter(p_change:Number) {
		_counter = _counter + p_change;
	}
	
	public function getCounter():Number {
		return _counter;
	}
	
	public function resetTileType() {
		_elementType = _elementTypes[_originalType];
	}
}